var app = getApp();
import ajaxhelper from '../../utils/ajaxhelper.js';
import checkLogin from '../../utils/checkLogin.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName: '',
    times: '',
    pkgCutId:'',
    avatarUrl:'',
    isBind:false //是否绑定手机号
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    checkLogin.login(this, function (res) {
      console.log(res)
    })
    console.log(options)
    var userName = options.userName;
    var date = options.date;
    var times = new Date(+date).format("yyyy-MM-dd");
    var pkgCutId = options.pkgCutId;
    var avatarUrl = options.avatarUrl;
    var coverMain = options.coverMain;
    var name = options.name;
    var isBind = wx.getStorageSync('Token_date') && wx.getStorageSync('Token_date').isBind;
    this.setData({
      userName: userName,
      times:times,
      pkgCutId: pkgCutId,
      avatarUrl: avatarUrl,
      coverMain: coverMain,
      name: name,
      isBind: isBind
    })
    var token = wx.getStorageSync('Token_date') && wx.getStorageSync('Token_date').Token;
    ajaxhelper.get(app.globalData.frontJSHost + 'present/hasReceived/' + this.data.pkgCutId + '?token=' + encodeURIComponent(token), {}, this, this.isGet)
  },

  //检测是否领取
  isGet:function(res){
    if(res.data){
      
      var userName = this.data.userName;
      var coverMain = this.data.coverMain;
      console.log(userName)
      console.log(coverMain)
      wx.redirectTo({
        url: '../giveSuccess/giveSuccess?&userName=' + userName + '&coverMain=' + coverMain
      })
    }
  },

  //点击进入领取礼品卡
  giftCards:function(){
    var userName = this.data.userName;
    var times = this.data.times;
    var avatarUrl = this.data.avatarUrl;
    var pkgCutId = this.data.pkgCutId;
    var coverMain = this.data.coverMain;
    var name = this.data.name;
    // var param={};
    // var token = wx.getStorageSync('Token_date') && wx.getStorageSync('Token_date').Token;
    // console.log(token)
    // console.log(encodeURIComponent(token))
    // ajaxhelper.put(app.globalData.frontJSHost + "receive/"+this.data.pkgCutId+"?token=" + encodeURIComponent(token), param, this, this.setListData)
    wx.redirectTo({
      url: '../received/received?&userName=' + userName + '&times=' + times + '&avatarUrl=' + avatarUrl + '&pkgCutId=' + pkgCutId + '&coverMain=' + coverMain + '&name=' + name
    })
  },
})